package cn.css0209.applicationdemo190509.User;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import cn.css0209.applicationdemo190509.R;
import cn.css0209.applicationdemo190509.utils.OkHttp;
import cn.css0209.applicationdemo190509.utils.StatusBarUtil;

public class AddUserActivity extends AppCompatActivity {
    Button addBtn;
    EditText userNum,userName,userPwd,userPwdAgain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_user);
        topBar();
        userNum = findViewById(R.id.add_user);
        userName = findViewById(R.id.add_userName);
        addBtn = findViewById(R.id.add_btn);
        userPwd = findViewById(R.id.add_pwd);
        userPwdAgain = findViewById(R.id.add_pwd_again);
    }

    public void addUserBtn(View v){
        System.out.println("Registered Btn is Click");
        String user = userNum.getText().toString();
        String Username = userName.getText().toString();
        String userpwd = userPwd.getText().toString();
        String userpwd2 = userPwdAgain.getText().toString();
//        验证
        if(user.isEmpty() || Username.isEmpty() || userpwd.isEmpty() || userpwd2.isEmpty()) {
            Toast.makeText(AddUserActivity.this, "Please confirm that the information has been filled in all!", Toast.LENGTH_SHORT).show();
        }else if(user.length()<6) {
            Toast.makeText(this, "UserNumber length must be greater than 6", Toast.LENGTH_SHORT).show();
        }else if(userpwd.length()<6){
            Toast.makeText(this,"Password length must be greater than 6",Toast.LENGTH_SHORT).show();
        }else if(!userpwd.equals(userpwd2)){
            Toast.makeText(AddUserActivity.this,"The password entered twice is different!",Toast.LENGTH_SHORT).show();
        }else{
            OkHttp http = new OkHttp(this);
            http.addUser(user,Username,userpwd);
        }
    }

    //    沉浸状态栏
    public void topBar() {
        //当FitsSystemWindows设置 true 时，会在屏幕最上方预留出状态栏高度的 padding
        StatusBarUtil.setRootViewFitsSystemWindows(this, true);
        //设置状态栏透明
        StatusBarUtil.setTranslucentStatus(this);
        //一般的手机的状态栏文字和图标都是白色的, 可如果你的应用也是纯白色的, 或导致状态栏文字看不清
        //所以如果你是这种情况,请使用以下代码, 设置状态使用深色文字图标风格, 否则你可以选择性注释掉这个if内容
        if (!StatusBarUtil.setStatusBarDarkTheme(this, false)) {
            //如果不支持设置深色风格 为了兼容总不能让状态栏白白的看不清, 于是设置一个状态栏颜色为半透明,
            //这样半透明+白=灰, 状态栏的文字能看得清
            StatusBarUtil.setStatusBarColor(this, 0x55000000);
        }
    }
}
